home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr40 / radserv.zip / RADSETUP.C < prev    next >
C/C++ Source or Header  |  1995-01-23  |  4KB  |  177 lines

  1.  
  2.  
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <time.h>
  7.  
  8. #include "vsttype.h"
  9. #include "resource.h"
  10. #include "radextrn.h"
  11.  
  12. extern radparam_t rigInfo;
  13.  
  14. static radioinfo_t *rip;
  15.  
  16. static char defrx[16];
  17. static char deftx[16];
  18. static char rxbfo[4];
  19. static char txbfo[4];
  20. static int  radioflags;
  21.  
  22. #define RAD_RXONLY       0x000001
  23. #define RAD_ARXADJ       0x000002
  24.  
  25. static button_t BtnTab[3] = {
  26.     RAD_RXONLY,       IDB_SETUP_RXONLY,  0,
  27.     RAD_ARXADJ,       IDB_SETUP_TRANSRX,  0,
  28.     -1,             -1, 0,
  29. };
  30.  
  31.  
  32. static void
  33. radio_to_controls() /* store struct values for display in the dialog box */
  34. {
  35.     register radioinfo_t *rp = rip;
  36.     
  37.     sprintf(defrx,"%d", rp->ra_rxcenter);
  38.     sprintf(deftx,"%d", rp->ra_txcenter);
  39.     sprintf(rxbfo,"%s", rp->ra_rxbfo);
  40.     sprintf(txbfo,"%s", rp->ra_txbfo);
  41.     radioflags = rp->ra_flags;
  42. }
  43.  
  44. static void
  45. controls_to_radio() /* store dialog box values in internal struct(s) */
  46. {
  47.     register radioinfo_t *rp = rip;
  48.  
  49.     sscanf(defrx,"%d", &rp->ra_rxcenter);
  50.     sscanf(deftx,"%d", &rp->ra_txcenter);
  51.     sscanf(rxbfo,"%s", rp->ra_rxbfo);
  52.     sscanf(txbfo,"%s", rp->ra_txbfo);
  53.     rp->ra_flags = radioflags;
  54. }   
  55.  
  56.  
  57. static int
  58. check_radio_buttons(hwnd, wParam)
  59. HWND hwnd;
  60. WPARAM wParam;
  61. {
  62.     int cmd;
  63.  
  64.     cmd = LOWORD(wParam);
  65.     
  66.     switch (cmd) {
  67.     case IDOK:
  68.     case IDCANCEL:
  69.         return cmd;
  70.     default:
  71.         break;
  72.     }
  73.     
  74.     if (HIWORD(wParam) != BN_CLICKED)
  75.         return -1;
  76.  
  77.     switch (cmd) {
  78.     case IDB_SETUP_RXONLY:
  79.         radioflags ^= RAD_RXONLY;
  80.         goto bset;
  81.  
  82.     case IDB_SETUP_TRANSRX:
  83.         radioflags ^= RAD_ARXADJ;
  84.         /* Fall through to bset */
  85.         
  86.     bset:
  87.         setbuttons(hwnd, radioflags, BtnTab);
  88.         break;
  89.         
  90.      default: /* Warning: must return -1 */
  91.         break;
  92.      }
  93.      return -1;
  94. }
  95.  
  96.  
  97. static void
  98. setRadControls(hwnd)
  99. HWND hwnd;
  100. {    
  101.     SendDlgItemMessage(hwnd, IDC_SETUP_DEFRX, WM_SETTEXT, (WPARAM) 0,
  102.         (LPARAM) defrx);
  103.     SendDlgItemMessage(hwnd, IDC_SETUP_DEFTX, WM_SETTEXT, (WPARAM) 0,
  104.         (LPARAM) deftx);
  105.     SendDlgItemMessage(hwnd, IDC_SETUP_RXBFO, WM_SETTEXT, (WPARAM) 0,
  106.         (LPARAM) rxbfo);
  107.     SendDlgItemMessage(hwnd, IDC_SETUP_TXBFO, WM_SETTEXT, (WPARAM) 0,
  108.         (LPARAM) txbfo);
  109.  
  110.     setbuttons(hwnd, radioflags, BtnTab);
  111. }
  112.  
  113. static void
  114. getRadControls(hwnd)
  115. HWND hwnd;
  116. {
  117.     extern char *GetEditText(HWND, int, char *, int);
  118.  
  119.     GetEditText(hwnd, IDC_SETUP_DEFRX, defrx, sizeof(defrx));
  120.     GetEditText(hwnd, IDC_SETUP_DEFTX, deftx, sizeof(deftx));
  121.     GetEditText(hwnd, IDC_SETUP_RXBFO, rxbfo, sizeof(rxbfo));
  122.     GetEditText(hwnd, IDC_SETUP_TXBFO, txbfo, sizeof(txbfo));
  123. }
  124.  
  125. static BOOL CALLBACK
  126. RadioParamsProc(hwnd, message, wParam, lParam)
  127. HWND hwnd;
  128. UINT message;
  129. WPARAM wParam;
  130. LPARAM lParam;
  131. {
  132.         POINT *p;
  133.         int cmd;
  134.             
  135.         switch(message) {
  136.             case WM_INITDIALOG:
  137.                 p = DialogPos(Gwnd, hwnd);
  138.                 SendMessage(hwnd, DM_SETDEFID, (WPARAM) IDNONE, (LPARAM)0 );
  139.                 SendMessage(GetDlgItem(hwnd, IDOK), WM_SETFOCUS, 0, (LPARAM)0);
  140.                 setRadControls(hwnd);
  141.                 SetWindowPos(hwnd, 0, (int)p->x, (int)p->y, 0, 0,
  142.                          SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
  143.                 return TRUE;
  144.  
  145.             case WM_COMMAND:
  146.                 if ((cmd = check_radio_buttons(hwnd, wParam)) >= 0) {
  147.                     switch (cmd) {
  148.                     case IDOK:
  149.                         getRadControls(hwnd);
  150.                         EndDialog(hwnd, (WPARAM)TRUE);
  151.                         return TRUE;
  152.  
  153.                     case IDCANCEL:
  154.                         EndDialog(hwnd, (WPARAM)FALSE);
  155.                         return TRUE;
  156.                     }
  157.                 }
  158.                 break;
  159.  
  160.             default:
  161.                 break;
  162.         }
  163.         return FALSE;
  164. }
  165.  
  166. void
  167. RadioParams()
  168. {
  169.     int r;
  170.  
  171.     rip = &rigInfo.radio;
  172.     radio_to_controls();
  173.     r = DialogBox(NULL, MAKEINTRESOURCE(IDD_RAD_SETUP), Gwnd, RadioParamsProc);
  174.     if (r)
  175.         controls_to_radio();
  176. }
  177.